<!DOCTYPE html>
<html lang="zh-CN">
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"> 
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"georgeguoxv.gitee.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","Muse | Mist":220,"display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="websocket协议类似于http1.1协议的keep alive      Youtube教程多数编程语言都有现成的websocket库可以使用， 因为个人喜好原因，以Nodejs的socket.io库为例 使用Nodejs编写一个websocket多人线上共享编辑的appapp后端首先你要装好nodejs和npm，接着建一个新的文件夹，作为项目的根目录。 Nodejs需要库：socket.i">
<meta property="og:type" content="article">
<meta property="og:title" content="websocket协议和webrtc协议">
<meta property="og:url" content="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/index.html">
<meta property="og:site_name" content="George的博客">
<meta property="og:description" content="websocket协议类似于http1.1协议的keep alive      Youtube教程多数编程语言都有现成的websocket库可以使用， 因为个人喜好原因，以Nodejs的socket.io库为例 使用Nodejs编写一个websocket多人线上共享编辑的appapp后端首先你要装好nodejs和npm，接着建一个新的文件夹，作为项目的根目录。 Nodejs需要库：socket.i">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/image-20210418153113561.png">
<meta property="og:image" content="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/output-1618739874818.gif">
<meta property="article:published_time" content="2021-04-06T15:06:28.000Z">
<meta property="article:modified_time" content="2021-04-18T10:16:08.949Z">
<meta property="article:author" content="George Guo">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/image-20210418153113561.png">

<link rel="canonical" href="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>websocket协议和webrtc协议 | George的博客</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-K1BDW9XHBV"></script>
    <script>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-K1BDW9XHBV');
      }
    </script>


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?ec3fe06eb0228c5b6ef8635fb259b905";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">George的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">学习使我快乐</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://georgeguoxv.gitee.io/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/favicon-32x32.png">
      <meta itemprop="name" content="George Guo">
      <meta itemprop="description" content="本博客为纯静态网站">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="George的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          websocket协议和webrtc协议
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-04-06 23:06:28" itemprop="dateCreated datePublished" datetime="2021-04-06T23:06:28+08:00">2021-04-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-04-18 18:16:08" itemprop="dateModified" datetime="2021-04-18T18:16:08+08:00">2021-04-18</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="websocket协议"><a href="#websocket协议" class="headerlink" title="websocket协议"></a>websocket协议</h2><p>类似于http1.1协议的keep alive      <a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=2Nt-ZrNP22A&amp;t=472s">Youtube教程</a><br>多数编程语言都有现成的websocket库可以使用，</p>
<p>因为个人喜好原因，以Nodejs的socket.io库为例</p>
<h2 id="使用Nodejs编写一个websocket多人线上共享编辑的app"><a href="#使用Nodejs编写一个websocket多人线上共享编辑的app" class="headerlink" title="使用Nodejs编写一个websocket多人线上共享编辑的app"></a>使用Nodejs编写一个websocket多人线上共享编辑的app</h2><h3 id="app后端"><a href="#app后端" class="headerlink" title="app后端"></a>app后端</h3><p>首先你要装好nodejs和npm，接着建一个新的文件夹，作为项目的根目录。</p>
<p>Nodejs需要库：socket.io 和express </p>
<p>如果没有安装过socket.io和express，打开命令行（windows 为cmd），将路径切换到新建的文件夹下</p>
<p>windows使用命令：cd  /d  <em>这里是你的文件夹路径</em></p>
<p>输入：npm install express socket.io —save</p>
<p>这会在当前文件夹创建一个node_modules作为库目录，创建package.json和package-lock.json来记录这个项目当前的库依赖。</p>
<p>创建文件index.js作为服务器，并编辑index.js，如下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> express = <span class="built_in">require</span>(<span class="string">&#x27;express&#x27;</span>)<span class="comment">//导入express库</span></span><br><span class="line"><span class="keyword">const</span> app = express()<span class="comment">//创建express app</span></span><br><span class="line"><span class="keyword">const</span> server = <span class="built_in">require</span>(<span class="string">&#x27;http&#x27;</span>).Server(app)<span class="comment">//用Nodejs自带的http库服务器</span></span><br><span class="line"><span class="keyword">const</span> io = <span class="built_in">require</span>(<span class="string">&#x27;socket.io&#x27;</span>)(server)<span class="comment">//给服务器加上websocket功能</span></span><br><span class="line">app.use(express.static( __dirname ))<span class="comment">//服务器开始服务当前index.js所在文件夹下的所有文件</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">io.on(<span class="string">&#x27;connection&#x27;</span>, <span class="function">(<span class="params">socket</span>) =&gt;</span> &#123;<span class="comment">//当一个用户使用ws（websocket）连接到服务器时</span></span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&#x27;有一个用户连接了！&#x27;</span>) <span class="comment">//服务器提醒</span></span><br><span class="line"></span><br><span class="line"> socket.on(<span class="string">&#x27;message&#x27;</span>, <span class="function">(<span class="params">evt</span>) =&gt;</span> &#123;<span class="comment">//当用户通过ws发送消息时</span></span><br><span class="line">    <span class="built_in">console</span>.log(evt)            <span class="comment">//在服务器上显示消息内容 </span></span><br><span class="line">   socket.broadcast.emit(<span class="string">&#x27;message&#x27;</span>, evt)<span class="comment">//将这个消息发送给所有连接的用户</span></span><br><span class="line"></span><br><span class="line">  &#125;)</span><br><span class="line">  &#125;)</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">io.on(<span class="string">&#x27;disconnect&#x27;</span>, <span class="function">(<span class="params">evt</span>) =&gt;</span> &#123;<span class="comment">//当某个用户的ws连接断开时</span></span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&#x27;有用户断开了&#x27;</span>)&#125;) <span class="comment">//服务器提醒</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">server.listen(<span class="number">3000</span>) <span class="comment">//服务器开始运行在本机3000端口</span></span><br></pre></td></tr></table></figure>
<p>这时你在网页里打开  <a href="localhost:3000">localhost:3000</a>, 你会看到如下图：</p>
<p><img src="/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/image-20210418153113561.png" alt></p>
<p>这是因为index.js会服务同目录下的所有文件，但出于安全考虑，http服务器不会显示文件夹下的文件，防止蓄意不良的人探查服务器的结构。我们必须输入文件路径，而不是文件夹路径。</p>
<p>这时我们新建一个文件名为 1.txt，输入 localhost:3000/1.txt,就能访问到1.txt里的内容</p>
<h4 id="我的思路"><a href="#我的思路" class="headerlink" title="我的思路"></a>我的思路</h4><p>【1】只需每个用户在编辑文档的时候都发送ws命令给服务器，我们就可以在后端协调多个用户的操作了</p>
<p>【2】对于较小的文档，每个用户编辑后，都发送全文给所有在线用户，（我们就使用这个办法）</p>
<h3 id="app前端"><a href="#app前端" class="headerlink" title="app前端"></a>app前端</h3><p>多人同时对文本的处理，只需要很简单的html就能实现</p>
<p>html是浏览器使用最广泛的文件类型，浏览器通过运行html文件内的javascript，在用户与html交互时可以给予响应，还可以发送请求到远程服务器。</p>
<p>我们用简单的html语言写一个网页。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 首先，html文件以 &lt;html&gt; 开始 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span> </span><br><span class="line">    <span class="comment">&lt;!-- html网页的标题 在&lt;title&gt;和&lt;/title&gt;之间 --&gt;</span> </span><br><span class="line"><span class="tag">&lt;<span class="name">title</span>&gt;</span>这个网页支持实时合作编辑<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- html网页的主体 在&lt;body&gt;和&lt;/body&gt;中间  --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- h3代表三级标题 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">h3</span>&gt;</span>这个网页支持实时合作编辑<span class="tag">&lt;/<span class="name">h3</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- div代表一个块 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- textarea代表文本框 这里设置文本框背景色为深绿色 字体为白色 提示为：在这里输入你想要编辑的文本... --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">textarea</span> <span class="attr">rows</span>=<span class="string">&quot;30&quot;</span> <span class="attr">cols</span>=<span class="string">&quot;50&quot;</span> <span class="attr">id</span>=<span class="string">&quot;editor&quot;</span> <span class="attr">style</span>=<span class="string">&quot;background-color:darkgreen;color:#fff&quot;</span>  <span class="attr">placeholder</span>=<span class="string">&quot;在这里输入你想要编辑的文本...&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">textarea</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>这时我们有了html的各种元素,接下来需要javascript来实现和服务器之间的通信</p>
<p>首先，当我们需要在浏览器发起一个socket.io请求时，浏览器需要加载客户端的socket.io库 当初使用npm install socket.io时，下载就包含了客户端的库， 或者直接百度搜索<a target="_blank" rel="noopener" href="https://cdn.baomitu.com/socket.io">socket.io客户端CDN</a></p>
<p>   <code>&lt;script&gt;</code>代表运行javascript代码块 src代表代码块的资源地址 ./代表当前网页的url </p>
<p>./再加上相对路径就等于要请求的绝对路径url </p>
<p>其实更推荐使用cdn，因为用户使用cdn，可减少服务器流量负担，当你真正部署服务器时，需要考虑这些</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;../node_modules/socket.io-client/dist/socket.io.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 或者使用  &lt;script src=&quot;这里输入百度得到的cdn地址&quot;&gt;&lt;/script&gt;  --&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>接下来有了库，再新建一个<code>&lt;script&gt;</code>标签，开始写代码实现</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript"><span class="keyword">var</span> socket = io(<span class="string">&#x27;http://localhost:3000&#x27;</span>);<span class="comment">//建立ws连接到本地服务器</span></span></span><br><span class="line"></span><br><span class="line"><span class="javascript"><span class="keyword">const</span> editor = <span class="built_in">document</span>.getElementById(<span class="string">&quot;editor&quot;</span>)<span class="comment">//editor是先前html里的文本框元素</span></span></span><br><span class="line"><span class="javascript">editor.addEventListener(<span class="string">&quot;keyup&quot;</span>, <span class="function">(<span class="params">evt</span>) =&gt;</span> &#123;     <span class="comment">//当文本框检测到一次键盘按键时</span></span></span><br><span class="line"><span class="javascript">    <span class="keyword">const</span> text = editor.value                   <span class="comment">//获取文本框当前内容，将内容写入变量text</span></span></span><br><span class="line"><span class="javascript">    socket.send(text)                           <span class="comment">//将text发送给服务器</span></span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="javascript">socket.on(<span class="string">&#x27;message&#x27;</span>, <span class="function">(<span class="params">data</span>) =&gt;</span> &#123;                <span class="comment">//当收到服务器消息时</span></span></span><br><span class="line"><span class="javascript">    editor.value = data                         <span class="comment">//文本框内容更新为服务器的消息内容</span></span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span>                                       //javascript代码块结束</span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span>                                         //html结束</span><br></pre></td></tr></table></figure>
<p>视频演示</p>
<p><img src="/2021/04/06/websocket%E5%8D%8F%E8%AE%AE%E5%92%8Cwebrtc%E5%8D%8F%E8%AE%AE/output-1618739874818.gif" alt></p>
<h2 id="WebRTC协议"><a href="#WebRTC协议" class="headerlink" title="WebRTC协议"></a>WebRTC协议</h2><p>视频演示</p>
<iframe src="//player.bilibili.com/player.html?aid=544993144&bvid=BV1Wi4y1N74y&cid=317771332&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/%E5%BE%AE%E4%BF%A1.png" alt="George Guo 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/%E6%94%AF%E4%BB%98%E5%AE%9D.png" alt="George Guo 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/04/03/%E8%B4%B9%E9%A9%AC%E5%B0%8F%E5%AE%9A%E7%90%86%E5%92%8C%E6%AC%A7%E6%8B%89%E5%AE%9A%E7%90%86/" rel="prev" title="费马小定理和欧拉定理">
      <i class="fa fa-chevron-left"></i> 费马小定理和欧拉定理
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/04/24/PC%E5%BE%AE%E4%BF%A1hook%E9%80%86%E5%90%91%EF%BC%8C%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91/" rel="next" title="PC微信hook逆向，二次开发">
      PC微信hook逆向，二次开发 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
  <div class="comments" id="comments">
    
       
       <div id="gitment-container"></div>
       
    
  </div>

  

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=230 src="//music.163.com/outchain/player?type=0&id=401771073&auto=1&height=430"></iframe>

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#websocket%E5%8D%8F%E8%AE%AE"><span class="nav-number">1.</span> <span class="nav-text">websocket协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8Nodejs%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AAwebsocket%E5%A4%9A%E4%BA%BA%E7%BA%BF%E4%B8%8A%E5%85%B1%E4%BA%AB%E7%BC%96%E8%BE%91%E7%9A%84app"><span class="nav-number">2.</span> <span class="nav-text">使用Nodejs编写一个websocket多人线上共享编辑的app</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#app%E5%90%8E%E7%AB%AF"><span class="nav-number">2.1.</span> <span class="nav-text">app后端</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%88%91%E7%9A%84%E6%80%9D%E8%B7%AF"><span class="nav-number">2.1.1.</span> <span class="nav-text">我的思路</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#app%E5%89%8D%E7%AB%AF"><span class="nav-number">2.2.</span> <span class="nav-text">app前端</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#WebRTC%E5%8D%8F%E8%AE%AE"><span class="nav-number">3.</span> <span class="nav-text">WebRTC协议</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="George Guo"
      src="/images/favicon-32x32.png">
  <p class="site-author-name" itemprop="name">George Guo</p>
  <div class="site-description" itemprop="description">本博客为纯静态网站</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">8</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/George-Guo-tech" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;George-Guo-tech" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/GeorgeGuoXv" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;GeorgeGuoXv" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom gitee"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://m.bilibili.com/space/553832852" title="Bilibili → https:&#x2F;&#x2F;m.bilibili.com&#x2F;space&#x2F;553832852" rel="noopener" target="_blank"><i class="fa fa-fw fa-custom bilibili"></i>Bilibili</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://github.com/chengciming/wechatPc" title="https:&#x2F;&#x2F;github.com&#x2F;chengciming&#x2F;wechatPc" rel="noopener" target="_blank">微信机器人项目(C++,php,html5)</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://github.com/cspinstructor/my-crackmes" title="https:&#x2F;&#x2F;github.com&#x2F;cspinstructor&#x2F;my-crackmes" rel="noopener" target="_blank">C++逆向练习</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
<script src="/live2d/autoload.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/Justlovesmile/CDN/js/sakura.js"></script>
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
  <script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script><script src="/js/src/md5.min.js"></script>

<div id="gitalk-container"></div>
<script>

const gitalk = new Gitalk({
  clientID: '52d4fe3261227490009f',
  clientSecret: 'abf5c09c8aeb14f4bcbf49b9fc838aef6ef9bc14',
  repo: 'George-Guo-tech.github.io',      // The repository of store comments,
  owner: 'George-Guo-tech',
  admin: ['George-Guo-tech'],
  id: md5(location.pathname),      // Ensure uniqueness and length less than 50
  distractionFreeMode: false  // Facebook-like distraction free mode
})

gitalk.render('gitalk-container')
//   var gitment = new Gitment({
//   id: 'www.bibibigeorge.site',
//   owner: 'George-Guo-tech',
//   repo: 'George-Guo-tech.github.io',
//   oauth: {
//     client_id: '52d4fe3261227490009f',
//     client_secret: 'abf5c09c8aeb14f4bcbf49b9fc838aef6ef9bc14',
//   },
//   // ...
//   // For more available options, check out the documentation below
// })
//   // gitment.render('container')
//   gitment.render(document.getElementById('comments'))


jQuery(document).ready(function() {
    function c() {
        /* 排除首页（记得自行修改下首页地址） */
	if (location.href != "https://bibibigeorge.site") { document.title = document[a] ? "(つェ⊂)誒呀→《" + d + "》" : "(*´∇｀*) 咦好了→《" + d + "》" }
    }
    var a, b, d = document.title;
    "undefined" != typeof document.hidden ? (a = "hidden", b = "visibilitychange") : "undefined" != typeof document.mozHidden ? (a = "mozHidden", b = "mozvisibilitychange") : "undefined" != typeof document.webkitHidden && (a = "webkitHidden", b = "webkitvisibilitychange");
    "undefined" == typeof document.addEventListener && "undefined" == typeof document[a] || document.addEventListener(b, c, !1)
});
</script>

	<script type="text/javascript" src="/js/src/clicklove.js"></script>
	  <!-- <script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script> -->
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">George Guo</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>
  <div class="addthis_inline_share_toolbox">
    <script src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-6059e3bca1c1bc91" async="async"></script>
  </div>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
<span id="busuanzi_container_site_pv">
| 本站总访问量<span style="color:#FA8072" id="busuanzi_value_site_pv"></span>次
</span>
<span id="busuanzi_container_site_uv">
| 本站访客数<span style="color:#FA8072" id="busuanzi_value_site_uv"></span>人次
</span>





        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>

















  

  

  

  
</body>
</html>
